package com.lyxs916.testlibrary.recyclertest;

import android.content.Context;
import android.view.ViewGroup;

import com.lyxs916.appbaselibrary.core.http.BaseHttpCallback;
import com.lyxs916.appbaselibrary.core.presenter.BasePresenter;
import com.lyxs916.common.HostType;
import com.lyxs916.httpresponse.HttpResult;
import com.lyxs916.network.BaseHttpRequest;
import com.lyxs916.network.HttpCallBack;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 说明:
 * 作者： 杨阳; 创建于：  2017-06-08  16:09
 */
public class RefreshTestPresenter extends BasePresenter<IListTestParentView.IRefreshTestView> {

    /**
     * @param first
     * @param viewGroup
     */
    public void requestHttpData(boolean first, ViewGroup viewGroup) {

        HttpCallBack.Builder buider = new BaseHttpCallback.BaseBuilder(mvpView)
                .setShowLoading((Context) mvpView, first)
                .setCancelable(true)
                .setHint("正在加载...")
                .setShowDefeatView(first, viewGroup)
                .setHostType(HostType.TYPE_TWO);


        final BaseHttpCallback httpCallBack = new BaseHttpCallback<HttpResult<List<ListTestBean>>>(buider) {
            @Override
            public void onSuccess(final HttpResult<List<ListTestBean>> result) {
                super.onSuccess(result);
                if (result != null) {
                    try {
                        mvpView.resultData(result.getData());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }

            }
        };

        //http://w-mall.lsh-cat.com:9998/tools/app_api.ashx?action=GetSecondHandEquipment&pageSize=20&pageIndex=1
        Map<String, String> map = new HashMap<>();
        map.put("action", "GetSecondHandEquipment");
        map.put("pageSize", "20");
        map.put("pageIndex", 1+"");
        BaseHttpRequest.executePost(httpCallBack, "tools/app_api.ashx", map);

    }


}
